package com.example.homework_03;

import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;

public class CustomDialog extends DialogFragment {

    private CustomListener listener ;
    private EditText t1 ;
    private EditText t2 ;

    CustomDialog(CustomListener listener){
        this.listener = listener ;
    }

    interface CustomListener{
        void onclick(String str1,String str2) ;
    }

    @Override
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()) ;
        LayoutInflater inflater = requireActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.custom,null) ;

        t1 =(EditText)view.findViewById(R.id.editTextTextPersonName) ;
        t2 =(EditText)view.findViewById(R.id.editTextTextPersonName2) ;
        TextView tv = (TextView)view.findViewById(R.id.textView2) ;
        tv.setText("自定义对话框");

        builder.setView(view).setTitle("自定义对话框")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        listener.onclick(t1.getText().toString(),t2.getText().toString());
                    }
                });
        return builder.create() ;
    }
}
